#include "stack.h"
void InitStack(Stack *stack)
{
    stack->Size=16;
    stack->Base=(void **)calloc(stack->Size,sizeof(void *));
    stack->Top=0;
}

void DropStack(Stack *stack)
{
    free(stack->Base);
}

void * PopStack(Stack *stack)
{
    if(stack->Top)
    {
        stack->Top--;
        return stack->Base[stack->Top];
    }
    else
    {
	return NULL;
    }
}

void PushStack(Stack *stack,void *e)
{
    if( stack->Top >= stack->Size )
    {
	stack->Size+=16;
        stack->Base=(void **)realloc(stack->Base,stack->Size*sizeof(void *));
    }
    *(stack->Base+stack->Top)=e;
    stack->Top++;
    return;
}

void EmptyStack(Stack *stack)
{
    stack->Top=0;
}

int StackIsEmpty(Stack *stack)
{
    return !stack->Top;
}

void GetTop(Stack *stack,void **e)
{
    if(stack->Top)
    {
	*e=stack->Base+stack->Top-1;
    }
    else
    {
	e=NULL;
    }
}
